package com.cocos.game;

import android.os.Build;

import com.cocos.game.cocosDto.NativeInitDataDto;
import com.cocos.lib.CocosActivity;
import com.cocos.lib.JsbBridgeWrapper;

import org.json.JSONObject;

public class NativeBridgeMgr {
    private CocosActivity _cocosActivity;
    private JsbBridgeWrapper _jbw = JsbBridgeWrapper.getInstance();
    public NativeBridgeMgr( CocosActivity cocosActivity){
        this.initEvent();
    }
    private void initEvent(){
        this._jbw.addScriptEventListener(NativeBridgeType.REQ_INIT_DATA,this::onReq_init_data);
    }

    private void onReq_init_data(String s) {
        NativeInitDataDto initDataVo = new NativeInitDataDto();
        try {
            initDataVo.deviceID = DeviceUtils.getDeviceId();
            initDataVo.model = Build.MODEL;
            initDataVo.androidVersion = Build.VERSION.RELEASE;
            initDataVo.sdkVersion = Build.VERSION.SDK_INT;
        } catch (Exception e) {
            e.printStackTrace();
        }
        JSONObject json = new JSONObject(initDataVo);
       this.sendEvent(NativeBridgeType.RES_INIT_DATA,JSONObject.toString());
    }
    private void sendEvent(String type, JSONObject data){
        this._jbw.dispatchEventToScript(type,data.toString());
    }
}
